
"use strict";

angular.module('app.personal').controller('PerUserCtrl', function ($scope,$http,$cookieStore,personalCenterHttp,userHttpS) {
	//配置分页基本参数
    $scope.paginationConf = {
        currentPage: 1,
        itemsPerPage: 10,
        pagesLength: 5,
        totalItems:20,
        perPageOptions: [10, 20, 30, 40, 50],
        onChange: function(){
        }
    };
    
    //获得用户个人信息
    $http.get(baseurls+"/detail/user?id="+$cookieStore.get("user"),{withCredentials:true}).then(function(res){
        // console.log(res.data);
        if(res.data.ret == 1){
            $scope.user = res.data.info;
            $scope.user.picture_url = "styles/img/avatars/avatar.jpg";
        }else{

        }
    })

    //修改用户名
    $scope.edit_username = function (){
        if($(".edil_name_txt").val() != ""){
            $(".preUser_name").text($(".edil_name_txt").val());
            var change_name = { name:$(".edil_name_txt").val() };
            $http.put(baseurls+"/data/user?id=="+$cookieStore.get("user"),change_name).then(function(res){
                // console.log(res.data);
                if(res.data.ret == 1){
                    new Notify('success','用户名更改成功');
                }else{
                    new Notify('fail','用户名更改失败');
                }
            })
            $(".edil_name_txt_box").hide();
            $(".edil_name_txt").val("");
        }else {
            $(".edil_name_txt_box").hide();
        }  
    }
    
    //修改手机号码
    $scope.edit_phone = function (){
        if($(".edil_call_txt").val() != "" && $(".edil_call_txt").val().length == 11 && !isNaN($(".edil_call_txt").val())){
            $(".preUser_call").text($(".edil_call_txt").val());
            $(".call_bind").text($(".edil_call_txt").val());
            var change_tele = { tele: $(".edil_call_txt").val() };
            $http.put(baseurls+"/data/user?id=="+$cookieStore.get("user"),change_tele).then(function(res){
                // console.log(res.data);
                if(res.data.ret == 1){
                    new Notify('success','手机号码更改成功');
                }else{
                    new Notify('fail','手机号码更改失败');
                }
            })
            $(".edil_call_txt_box").hide();
            $(".edil_call_txt").val("");
        }else {
            alert("请输入正确手机号码");
        }
    }
    
});